# import time,random
# import asyncio

# async def task(i):
#     await asyncio.sleep(1)
#     print(str(i)+"正在工作")


# def set_task():
    
#     #创建loop模块
#     loop = asyncio.get_event_loop()
#     #创建任务
#     tasks = [task(i) for i in range(3)]
#     #把任务加到队列中
#     runtask = asyncio.wait(tasks)
#     #启动任务
#     loop.run_until_complete(runtask)

   
# start = int(time.time())
# set_task()
# end = int(time.time())
# print("执行了"+str(end-start))
import math
# 二分法查询，排序
list = [1,6,3,8,5,7]
#排序
list1 = sorted(list)
#[1,3,5,6,7,8]
def binary_search(nums, target):
    i = 0
    j = len(nums) - 1
    while i <= j:
        m = int((i + j) / 2)
        print("m"+str(m))
        if target == nums[m]:
            return m
        elif target > nums[m]:
            i = m + 1
        else:
            j = m - 1

# print(binary_search(list1,1))
print(binary_search(list1,3))
# print(binary_search(list1,8))
# print(binary_search(list1,9))
# def search(list1,number):
#     start =0
#     end = len(list1)-1
   
#     while True:
#         mid = int((start+end)/2)
#         if number == list1[mid]:
#             return mid
#         elif number >list1[mid]:
#             start=mid+1
#         else:
#             end=mid-1
        
#     return '-1'

# print(search(list1,5))
# print(search(list1,7))
# print(search(list1,8))
# print(search(list1,9))